package com.qfedu.edu.controller;

import com.qfedu.edu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xiaobobo
 * @title: UserController
 * @projectName CD-Java-FY-2401-Springboot-Parent
 * @description: TODO
 * @date 2024/9/10  10:25
 */
@Controller
@RequestMapping("/users")
public class UserController {

    /**
     * 向Demo1.html跳转
      * @return
     */
    @GetMapping("/toDemo1Page")
    public String toDemo1Page(Model model){
        model.addAttribute("username","小波波");
        model.addAttribute("age",18);

        List<User> userList=new ArrayList<>();
        for (int i = 0; i <5 ; i++) {
             userList.add(new User(i+1,"用户名:"+i,"密码:"+i));
        }
        //最后将数据放到域对象中去
        model.addAttribute("userList",userList);
        //下面该这个域对象添加一个对象进去
        User user = new User(1, "中国", "1110");
        //然后将这个对象放到域对象中去
        model.addAttribute("user",user);
        model.addAttribute("className","class1");
        return "/Demo1.html";
    }


    /**
     * 跳转到首页去
     * @return
     */
    @GetMapping("toIndexPage")
    public String toIndexPage(){
        return "/index.html";
    }


    /**
     * 转发到服务器的内部
     * @return
     */
    @GetMapping("test")
    @ResponseBody
    public Object test(){
        return "这里来了";
    }

}
